package com.zjj.learn.designmodel.work.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxyFactory2 implements InvocationHandler {

    private  MySelf mySelf;

    public JdkProxyFactory2(MySelf mySelf) {
        this.mySelf = mySelf;
    }

    public Object getProxy(){
        return Proxy.newProxyInstance(
                this.getClass().getClassLoader(),
                mySelf.getClass().getInterfaces(),
                this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("调用方法前");
        Object invoke = method.invoke(mySelf, args);
        System.out.println("调用方法后");
        return invoke;
    }
}
